<template>
  <!-- 一级路由的坑 -->
  <!-- <KeepAlive v-if="$route.meta.iskeepalive">
    <RouterView />
  </KeepAlive> -->
  <p>
    <router-link to="/home">首页</router-link>
    <router-link to="/category">分类</router-link>
    <router-link to="/car">购物车</router-link>
    <router-link to="/mine">我的</router-link>
  </p>


  <router-view v-slot="{ Component }">
    <Transition name="slide-fade">
      <keep-alive :exclude="arr">
        <component :is="Component" />
      </keep-alive>
    </Transition>
  </router-view>

  <!-- <p>{{ arr }}</p> -->



  <!-- <router-view v-slot="{ Component }">
    <keep-alive :exclude="arr">
      <component :is="Component" />
    </keep-alive>
  </router-view> -->
</template>

<script>
import { RouterLink, RouterView } from 'vue-router';
export default {
  data() {
    return {

    }
  },
  computed: {
    arr() {
      let newArr = []; // 不缓存的组件名组成的数组
      if (this.$route.meta.iskeepalive == false) {
        // 当路由切换的时候,此时依赖的项发生变化,计算属性重新计算,
        newArr.push(this.$route.name)
      }
      return newArr
    }
  }
}

</script>

<style scoped>
.slide-fade-enter-active {
  transition: all 0.5s ease-out;
}

.slide-fade-leave-active {
  transition: all 0.5s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateX(20px);
  opacity: 0;
}
</style>
